<%@ taglib prefix="p" uri="/WEB-INF/tld/privilege.tld" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%     
	String path = request.getContextPath();     
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";     
%> 
<%response.setHeader("cache-control","public"); %>
<html>
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  <title>新闻列表</title>
  <base href="<%=basePath%>"/>
  <%@ include file="../list_include.jsp"%>
  
  <style type="text/css"> 
	fieldset,table,tr,td {margin:0; padding:0;}
	td {padding:0 5px 0 10px;}
	form label {font-weight:bold;}
	#itemTable {margin:5px 0;}
  </style>

  <script type="text/javascript">
	$(document).ready(function() { 
       	$("#notiTable").tablesorter({theme:'green', widgets:['zebra', "resizable"]});
       	
       	$("#btn_pageUp").click(function(){
			var curPage = $("#curPage").val();
			$("#curPage").val(parseInt(curPage) - 1);
			$("#notiForm").submit();
       	});
       	
       	$("#btn_pageDown").click(function(){
       		var curPage = $("#curPage").val();
			$("#curPage").val(parseInt(curPage) + 1);
			$("#notiForm").submit();
       	});

        $("#btn_insert").click(function(){
            var queryString = $("#itemForm").formSerialize();
            queryString = encodeURIComponent(queryString);
            location.href = "<%=basePath%>comprehensive/news/insert.do?qs=" + queryString;
        });
        
        $("#btn_search").click(function(){
            $("#curPage").val(1);
            $("#notiForm").submit();
        });

        $("#btn_change").click(function(){
            var page = parseInt($("#selectPage").val());
            var curPage = parseInt($("#curPage").val());
            if(curPage == page) return;
            $("#curPage").val(parseInt(page));
            $("#notiForm").submit();
        });
	});  
	
	function setRead(id) {
		   $.post("<%=basePath%>/notification/setRead.do", { id: id},
			 function(data){
			   //由JSON字符串转换为JSON对象
			   var obj = eval('(' + data + ')');
			   if(obj.code)
			   {
				  alert("已读成功！");
				  window.parent.location.reload();
			   };
		   });
	}
  </script>
 </head>

 <body>
  <div>
    <fieldset>
      <legend>查询条件：</legend>
      <form id="notiForm" method="post" action="notification/list.do">
        <table>
          <tr>
            <td><label for="title">标题：</label></td>
            <td><input type="text" name="title" id="title" value="${title}" style="width:150px;" /></td>
            <td><label >状态：</label></td>
            <td>
              <select name="isRead" id="isRead">
                 <option value = "1"  <c:if test="${isRead == 1}"> selected="selected"</c:if>>未读</option>
                 <option value = "0"  <c:if test="${isRead == 0}"> selected="selected"</c:if>> 已读</option>
              </select>
            </td>
            <td><input type="submit" id="btn_search" name="btn_search" value="查询" style="width:80px;" /></td>
          </tr>
        </table>
      
        <input type="hidden" name="curPage" id="curPage" value="${curPage}" />
        <input type="hidden" name="totalPage" id="totalPage" value="${totalPage}" />
      </form>
    </fieldset>
  </div>
  
  <div>
  	<table id="notiTable" class="tablesorter">
	  <thead> 
	    <tr> 
          <th width="30%">标题</th> 
          <th width="30%">内容</th>
          <th>时间</th>
          <th>发送人</th>
          <th>接收人</th>
          <th>状态</th>
          <th>操作</th>
 	    </tr> 
	  </thead>
	  <tbody>
	  	<c:forEach items="${notiList}" var="n" varStatus="status">
	  	<tr>
	  	  <td>${n.title}</td>
	  	  <td>${n.content}</td>
          <td><fmt:formatDate value="${n.createTime }" type="both" dateStyle="medium" timeStyle="medium" /></td>
          <td>${n.fromUserCnname }</td>
          <td>${n.toUserCnname }</td>
          <td>
          <c:if test="${n.isRead == 1}">
                                      未读
          </c:if>
          <c:if test="${n.isRead == 0}">
                                     已读
          </c:if>
          </td>
          <c:if test="${n.isRead == 1}">
            <td>
	  	     <a href="#" onclick="javascript:setRead('${n.id}'); return false;">设置已读</a>
	  	    </td>
          </c:if>
           <c:if test="${n.isRead == 0}">
            <td>
	  	                    设置已读 
	  	    </td>
          </c:if>
	  	 
	  	</tr>
	  	</c:forEach>
	  </tbody>
  	</table>
  </div>

  <div>
      <div style="text-align:right;">
        <c:if test="${curPage <= 1}"><input type="button" disabled="disabled" id="btn_pageUp" value="上一页"/></c:if>
        <c:if test="${curPage > 1}"><input type="button" id="btn_pageUp" value="上一页"/></c:if>
        <c:if test="${curPage >= totalPage}"><input type="button" id="btn_pageDown" disabled="disabled" value="下一页"/></c:if>
        <c:if test="${curPage < totalPage}"><input type="button" id="btn_pageDown" value="下一页"/></c:if>
                   共${totalPage}页/共${totalRecords}条
        <select id="selectPage" style="width: auto;">
            <c:forEach var="i" begin="1" end="${totalPage}">
                <option id="${i}" <c:if test="${i == curPage}">selected="selected"</c:if>>${i}</option>
            </c:forEach>
        </select>
        <input id="btn_change" type="button" value="转至" />
      </div>
  </div>
 </body>
</html>

